﻿using System;
using Guia.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Guia.Elements;
using WpfTestApplication;

namespace GuiaTest
{
    /// <summary>
    /// Summary description for LabelTest
    /// </summary>
    [TestClass]
    public class ScrollBarTest : AbstractWindowTest
    {
        public ScrollBarTest()
        {
        }

        protected override Type TestWindowType()
        {
            return typeof(ScrollBarTestWindow);
        }

        protected override string TestWindowName()
        {
            return "ScrollBarTestWindow";
        }

        [TestMethod]
        public void TestSmallIncrese()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            TextBox textBox = window.Get<TextBox>("txtScrollValue");
            Assert.AreEqual("", textBox.Value);
            scrollBar.SmallIncrease();
            Assert.AreEqual("0.1", textBox.Value);
            Assert.AreEqual(0.1, scrollBar.Value);
            scrollBar.SmallIncrease();
            scrollBar.SmallIncrease();
            Assert.AreEqual("0.3", textBox.Value);
            Assert.AreEqual((float)0.3, (float)scrollBar.Value);
        }

        [TestMethod]
        public void TestLargeIncrease()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            TextBox textBox = window.Get<TextBox>("txtScrollValue");
            scrollBar.LargeIncrease();
            scrollBar.LargeIncrease();
            Assert.AreEqual("2", textBox.Value);
            Assert.AreEqual(2, scrollBar.Value);
        }

        [TestMethod]
        public void TestSmallDecrease()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            TextBox textBox = window.Get<TextBox>("txtScrollValue");
            scrollBar.LargeIncrease();
            scrollBar.SmallDecrease();
            scrollBar.SmallDecrease();
            Assert.AreEqual("0.8", textBox.Value);
            Assert.AreEqual(0.8, scrollBar.Value);
        }

        [TestMethod]
        public void TestLargeDecrease()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            TextBox textBox = window.Get<TextBox>("txtScrollValue");
            scrollBar.LargeIncrease();
            scrollBar.LargeIncrease();
            scrollBar.LargeDecrease();
            Assert.AreEqual("1", textBox.Value);
            Assert.AreEqual(1, scrollBar.Value);
        }

        [TestMethod]
        public void TestValue()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            TextBox textBox = window.Get<TextBox>("txtScrollValue");
            scrollBar.Value = 3.2;
            Assert.AreEqual("3.2", textBox.Value);
            Assert.AreEqual(3.2, scrollBar.Value);
        }

        [TestMethod]
        public void TestMinimum()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            Assert.AreEqual(0, scrollBar.Minimum);
        }

        [TestMethod]
        public void TestMaximum()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            Assert.AreEqual(10, scrollBar.Maximum);
        }

        [TestMethod]
        public void TestSmallChange()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            Assert.AreEqual(0.1, scrollBar.SmallChange);
        }

        [TestMethod]
        public void TestLargeChange()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            Assert.AreEqual(1, scrollBar.LargeChange);
        }

        [TestMethod]
        public void TestSmallIncrease()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            scrollBar.SmallIncrease();
            Assert.AreEqual(0.1, scrollBar.Value);
            Assert.AreEqual("0.1", window.Get<TextBox>("txtScrollValue").Value);
        }

        [TestMethod, ExpectedException(typeof(OperationNotSupportedException))]
        public void TestToLargeValue()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            scrollBar.Value = 20;
        }

        [TestMethod, ExpectedException(typeof(OperationNotSupportedException))]
        public void TestToSmallValue()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            scrollBar.Value = -10;
        }

        [TestMethod, ExpectedException(typeof(OperationNotSupportedException))]
        public void TestSmallIncreaseInvalidValue()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            scrollBar.Value = 10;
            scrollBar.SmallIncrease();
        }

        [TestMethod, ExpectedException(typeof(OperationNotSupportedException))]
        public void TestSmallDecreaseInvalidValue()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            scrollBar.Value = 0;
            scrollBar.SmallDecrease();
        }

        [TestMethod, ExpectedException(typeof(OperationNotSupportedException))]
        public void TestLargeIncreaseInvalidValue()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            scrollBar.Value = 9.9;
            scrollBar.LargeIncrease();
        }

        [TestMethod, ExpectedException(typeof(OperationNotSupportedException))]
        public void TestLargeDecreaseInvalidValue()
        {
            ScrollBar scrollBar = window.Get<ScrollBar>("scrollBarTest");
            scrollBar.Value = 0.1;
            scrollBar.LargeDecrease();
        }
    }
}
